<template>
  <!-- 计算公式维护 -->
  <base-breadcrumb :title="$route.meta.title">
    <a-row
      :gutter="10"
      class="page-height"
    >
      <!-- 树搜索 -->
      <a-col
        :span="6"
        class="permission-collapsed"
        :class="{ 'permission-tree-collapsed': collapsed }"
      >
        <a-card
          :style="{ border: collapsed ? 'none' : 'border: 1px solid #e8e8e8' }"
          class="page-height-tree"
        >
          <title-name title="组织架构" />
          <PermissionTreeOrganization
            :collapsed.sync="collapsed"
            @select="handleSelect"
          />
        </a-card>
      </a-col>
      <a-col
        :span="18"
        class="permission-collapsed page-height-list-wrapper"
        :style="collapsed ? 'width:calc(100% - 10px)' : ''"
      >
        <searchData
          :search-data="searchArr"
          @search="search"
        />

        <a-card class="page-height-list">
          <!-- 表格 -->
          <list-table
            ref="table"
            tableLayout="fixed"
            size="default"
            rowKey="id"
            :columns="columns"
            :request="loadData"
            :alert="true"
            show-size-changer
            show-quick-jumpers
            showPagination="auto"
          >
            <template
              slot="action"
              slot-scope="text, record"
            >
              <MoreButton>
                <a
                  v-btnPermission="'pm_048_loo_01'"
                  @click="handleManage(0, record)"
                >查看</a>
                <!-- 编辑 -->
                <span v-if="(record.auditStatus == 'DRAFT' || record.auditStatus == 'REJECTED')&&hideBuquBtn()">
                  <a @click="handleManage(1, record)">编辑</a>
                </span>
                <!-- 删除 -->

                <span v-if="record.auditStatus === 'PAST' || record.auditStatus === 'SUBMITTED' || record.auditStatus === 'REJECTED' || record.auditStatus === 'ABOLISH'">
                  <approval-button
                    :status="record.auditStatus"
                    :id="record.id"
                  ></approval-button>
                </span>
              </MoreButton>
            </template>
            <template
              slot="auditStatus"
              slot-scope="text, record"
            >
              <list-status
                :status="record.auditStatus"
                :isApproval="true"
                conversion="en"
                :text="text"
              ></list-status>
            </template>
          </list-table>
        </a-card>
      </a-col>
    </a-row>
  </base-breadcrumb>
</template>

<script>
import { STable } from '@/components' // 表格
import BasePage from '@/views/basePage' // 基础配置
import { api } from '@/api/project/performanceAnalysis'
import MoreButton from '@/components/MoreButton'
import PermissionTreeOrganization from '@/components/businessComponents/PermissionTreeOrganization'

import { typeListApproval1 } from '@/utils/util'
const columns = [
  {
    title: '序号',
    width: 80,
    dataIndex: 'index',
    customRender() {
      return arguments[2] + 1
    }
  },
  {
    title: '分公司',
    dataIndex: 'branchCompanyName',
    width: 100,
    ellipsis: true
  },
  {
    title: '项目名称',
    width: 100,
    dataIndex: 'projectName',
    ellipsis: true
  },
  {
    title: '月份',
    width: 100,
    dataIndex: 'month',
    ellipsis: true
  },
  {
    title: '当期累计完成产值/亿元',
    dataIndex: 'completionTotal',
    width: 100,
    ellipsis: true
  },
  {
    title: '产值完成率',
    dataIndex: 'completionRate',
    width: 100,
    ellipsis: true
  },
  {
    title: '人均产值/万元',
    dataIndex: 'completionPre',
    width: 100,
    ellipsis: true
  },
  {
    title: '工期履约率',
    dataIndex: 'periodRate',
    width: 100,
    ellipsis: true
  },
  {
    title: '节点按时完成率',
    dataIndex: 'nodeRate',
    width: 100,
    ellipsis: true
  },
  {
    title: '实名制出勤率',
    dataIndex: 'realnameRate',
    width: 100,
    ellipsis: true
  },
  {
    title: '顾客满意度',
    dataIndex: 'satisfaction',
    width: 100,
    ellipsis: true
  },
  {
    title: '状态',
    dataIndex: 'auditStatus',
    width: 100,
    scopedSlots: { customRender: 'auditStatus' }
  },
  {
    title: '操作',
    dataIndex: 'action',
    width: 180,
    scopedSlots: { customRender: 'action' }
  }
]
const searchArr = [
  {
    name: '月份',
    type: 'monthRange',
    value: 'mealMonthTime',
    attr: {
      rangeFormat: ['monthStart', 'monthEnd']
    }
  },

  {
    name: '状态',
    value: 'auditStatus',
    type: 'select',
    data: typeListApproval1
  }
]
export default {
  name: 'a' + Date.now(),
  extends: new BasePage(),
  components: {
    STable,
    MoreButton,
    PermissionTreeOrganization
  },
  data() {
    this.columns = columns
    this.searchArr = searchArr
    return {
      queryParam: {}, // 查询参数
      select: {},
      collapsed: false,
      removeApi: { remove: api.delNoAssessment },
      loadData: async (parameter) => {
        this.queryParam.branchCompanyId = undefined
        this.queryParam.projectId = this.select.projectId || undefined
        if (this.select.tageCode === 'BC') {
          this.queryParam.branchCompanyId = this.select.orgId
        }
        const requestParameters = Object.assign({}, parameter, { query: this.queryParam })

        return api.listLvyueProject(requestParameters).then((res) => {
          return res
        })
      }
    }
  },
  methods: {
    //搜索
    search(value) {
      value && (this.queryParam = value)
      this.$refs.table.refresh(true)
    },
    /**
     * @description: 树选中
     * @param {object} node 节点对象
     * @return {void}
     */
    handleSelect(node) {
      this.select = node
      if (this.select.tageCode != 'CO') {
        this.$refs.table.refresh(true)
      }
    },
    // 操作栏
    async handleManage(type, record) {
      let query = {
        editModel: type
      }
      if (record && record.id) {
        query.id = record.id
      }
      this.$router.push({
        name: 'updateProjectPerformanceAnalysis',
        query
      })
    }
  }
}
</script>
